package com.rabbiter.oes.controller;

import com.rabbiter.oes.entity.ApiResult;
import com.rabbiter.oes.entity.MultiQuestion;
import com.rabbiter.oes.serviceimpl.MultiQuestionServiceImpl;
import com.rabbiter.oes.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//单选题
@RestController
public class MultiQuestionController {

    @Autowired
    private MultiQuestionServiceImpl multiQuestionService;

    @GetMapping("/multiQuestionId")
    public ApiResult findOnlyQuestion() {
        MultiQuestion res = multiQuestionService.findOnlyQuestionId();
        return ApiResultHandler.buildApiResult(200,"查询成功",res);
    }


    @PostMapping("/MultiQuestion")
    public ApiResult add(@RequestBody MultiQuestion multiQuestion) {
        int res = multiQuestionService.add(multiQuestion);
        if (res != 0) {

            return ApiResultHandler.buildApiResult(200,"添加成功",res);
        }
        return ApiResultHandler.buildApiResult(400,"添加失败",res);
    }

    @PostMapping("/editMultiQuestion")
    public ApiResult edit(@RequestBody MultiQuestion multiQuestion) {
        int res = multiQuestionService.edit(multiQuestion);
        if (res != 0) {

            return ApiResultHandler.buildApiResult(200,"修改成功",res);
        }
        return ApiResultHandler.buildApiResult(400,"修改失败",res);
    }

    @GetMapping("/multiQuestion/batch")
    public ApiResult getBatchQuestions(@RequestParam Integer count,@RequestParam String subject) {
        System.out.println("count="+count);
        List<MultiQuestion> questions = multiQuestionService.findRandom(count,subject);
        return ApiResultHandler.buildApiResult(200, "查询成功", questions);
    }

    @GetMapping("/multiQuestion/sequence")
    public ApiResult getSequenceQuestions(@RequestParam String subject) {
        List<MultiQuestion> questions = multiQuestionService.findSequence(subject);
        return ApiResultHandler.buildApiResult(200, "查询成功", questions);
    }
}
